package com.sl.au.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;
import org.springframework.transaction.UnexpectedRollbackException;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import com.sl.au.entity.Account;
import com.sl.au.entity.Comment;
import com.sl.au.entity.EXDELoginInfo;
import com.sl.au.entity.Role;
import com.sl.au.entity.User;
import com.sl.au.repository.AccountRepository;
import com.sl.au.repository.CommentRepository;
import com.sl.au.repository.EXDELoginInfoRepository;
import com.sl.au.repository.UserRepository;
import com.sl.au.service.AccountService;
import com.sl.au.service.CommentService;
import com.sl.au.service.ModuleService;

@Service("CommentService")
@Transactional
public class CommentServiceImpl extends BaseServiceImpl implements CommentService {

	@Autowired
	CommentRepository commentRepository;

	@Override
	public CommentRepository getRepository() {
		return this.commentRepository;
	}

	@Override
	public void saveComment(Comment comment) {
		Comment newComment = null;
		if(!comment.getId().equals("")) {
			newComment = commentRepository.findOne(comment.getId());
			newComment.setUpdateTime(new Date());
		}else {
			newComment = new Comment();
			newComment.setCommentator(comment.getCommentator());
			newComment.setEventReport(comment.getEventReport());
		}
		newComment.setOperator(comment.getOperator());
		newComment.setScore(comment.getScore());
		newComment.setContent(comment.getContent());
		
		commentRepository.save(newComment);
	}

}
